package com.zhuhjay.model.domain;

import lombok.Data;

/**
 * @author ZhuHJay
 * @date 2023/4/24 22:05
 */
@Data
public class HttpResult<T> {

    private int code;
    private String message;
    private T data;

    private HttpResult(int code, String message) {
        this.code = code;
        this.message = message;
    }

    private HttpResult(int code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public static HttpResult<?> ok() {
        return new HttpResult<>(200, "操作成功");
    }

    public static HttpResult<?> ok(String message) {
        return new HttpResult<>(200, message);
    }

    public static <T> HttpResult<T> ok(T data) {
        return new HttpResult<>(200, "操作成功", data);
    }

    public static HttpResult<?> fail() {
        return new HttpResult<>(300, "操作错误");
    }

    public static HttpResult<?> fail(String message) {
        return new HttpResult<>(300, message);
    }

}
